package com.cndongtai.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.cndongtai.dao.BaseDao;
import com.cndongtai.dao.inter.LightStatusRecordMapper;
import com.cndongtai.po.LightStatusRecord;
import com.cndongtai.vo.PageForm;

@Repository("lightStatusRecordDao")
public class LightStatusRecordDao extends BaseDao implements LightStatusRecordMapper {

	@Override
	public boolean addLightStatus(LightStatusRecord status) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightStatusRecordMapper operation = sqlSession.getMapper(LightStatusRecordMapper.class);
			return operation.addLightStatus(status);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

	@Override
	public List<LightStatusRecord> queryLightStatusRecordList(Long userId, String lightNum, String panId) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			LightStatusRecordMapper operation = sqlSession.getMapper(LightStatusRecordMapper.class);
			return operation.queryLightStatusRecordList(userId, lightNum, panId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}
	
	@Override
	public int queryLightStatusRecordListCount(Map<String,Object> parms) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			LightStatusRecordMapper operation = sqlSession.getMapper(LightStatusRecordMapper.class);
			Integer count = operation.queryLightStatusRecordListCount(parms);
			return count==null?0:count;
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return 0;
	}
	
	@Override
	public List<LightStatusRecord> queryLightStatusRecordListPage(Map<String,Object> parms) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			LightStatusRecordMapper operation = sqlSession.getMapper(LightStatusRecordMapper.class);
			return operation.queryLightStatusRecordListPage(parms);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public List<LightStatusRecord> queryLightStatusRecordListByLightId(String startTime, String endTime, Long lightId) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			LightStatusRecordMapper operation = sqlSession.getMapper(LightStatusRecordMapper.class);
			return operation.queryLightStatusRecordListByLightId(startTime, endTime, lightId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public int queryLightChargeCountByUserId(Long userId) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			LightStatusRecordMapper operation = sqlSession.getMapper(LightStatusRecordMapper.class);
			return operation.queryLightChargeCountByUserId(userId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return 0;
	}

	@Override
	public LightStatusRecord queryLightLatestStatusRecord(Long userId,String lightId) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			LightStatusRecordMapper operation = sqlSession.getMapper(LightStatusRecordMapper.class);
			return operation.queryLightLatestStatusRecord(userId,lightId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}
	

}
